{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "using SymPy\n",
    "using LinearAlgebra\n",
    "\n",
    "δ = sympy.eye(2); \n",
    "ϵ = sympy.Matrix([0 1; -1 0]);\n",
    "g = sympy.diag(-1,1,1,1);"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 泡利矩阵"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2×2×4 Array{Sym,3}:\n",
       "[:, :, 1] =\n",
       " sqrt(2)/2          0\n",
       "         0  sqrt(2)/2\n",
       "\n",
       "[:, :, 2] =\n",
       "         0  sqrt(2)/2\n",
       " sqrt(2)/2          0\n",
       "\n",
       "[:, :, 3] =\n",
       "           0  -sqrt(2)*I/2\n",
       " sqrt(2)*I/2             0\n",
       "\n",
       "[:, :, 4] =\n",
       " sqrt(2)/2           0\n",
       "         0  -sqrt(2)/2"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "σ_0 = [1 0;0 1]/sqrt(Sym(2));\n",
    "σ_1 = [0 1;1 0]/sqrt(Sym(2));\n",
    "σ_2 = [0 -IM;IM 0]/sqrt(Sym(2));\n",
    "σ_3 = [1 0;0 -1]/sqrt(Sym(2));\n",
    "σ=[σ_0,σ_1,σ_2,σ_3];\n",
    "σ=[σ[μ][Σ,Σ1] for μ in 1:4,Σ in 1:2 ,Σ1 in 1:2];\n",
    "\n",
    "[σ[μ,Σ,Σ1] for Σ in 1:2, Σ1 in 1:2, μ in 1:4]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 零模四维矢量$k^a$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\[ \\left[ \\begin{array}{r}r\\\\r \\sin{\\left(θ \\right)} \\cos{\\left(ϕ \\right)}\\\\r \\sin{\\left(θ \\right)} \\sin{\\left(ϕ \\right)}\\\\r \\cos{\\left(θ \\right)}\\end{array} \\right] \\]"
      ],
      "text/plain": [
       "4-element Array{Sym,1}:\n",
       "               r\n",
       " r*sin(θ)*cos(ϕ)\n",
       " r*sin(θ)*sin(ϕ)\n",
       "        r*cos(θ)"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "@vars r positive=true θ ϕ  x real=true\n",
    "\n",
    "k = [r, r*sin(θ)*cos(ϕ), r*sin(θ)*sin(ϕ), r*cos(θ)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\begin{equation*}0\\end{equation*}"
      ],
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 验证零模\n",
    "\n",
    "sum(g[μ,υ]*k[μ]*k[υ] for μ in 1:4, υ in 1:4) .|> simplify  "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##  旋量$\\xi^A$的分量\n",
    "\n",
    "\n",
    "确定依据【精确到相差一个旗因子】：\n",
    "\n",
    "$$k^\\mu\\sigma_\\mu^{\\ \\ AA'}=\\xi^A\\bar{\\xi}^{A'}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\[ \\left[ \\begin{array}{r}a_{1} e^{i α1}\\\\a_{2} e^{i α2}\\end{array} \\right] \\]"
      ],
      "text/plain": [
       "2-element Array{Sym,1}:\n",
       " a1*exp(I*α1)\n",
       " a2*exp(I*α2)"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "@vars a1 a2 positive=true α α1 α2 real=true\n",
    "\n",
    "# 待定\n",
    "\n",
    "ξ =[a1*exp(IM*α1),a2*exp(IM*α2)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\[ \\left[ \\begin{array}{r}- a_{1}^{2} + \\frac{\\sqrt{2} r \\cos{\\left(θ \\right)}}{2} + \\frac{\\sqrt{2} r}{2}\\\\- a_{1} a_{2} e^{i α1} e^{- i α2} - \\frac{\\sqrt{2} i r \\sin{\\left(θ \\right)} \\sin{\\left(ϕ \\right)}}{2} + \\frac{\\sqrt{2} r \\sin{\\left(θ \\right)} \\cos{\\left(ϕ \\right)}}{2}\\\\- a_{2}^{2} - \\frac{\\sqrt{2} r \\cos{\\left(θ \\right)}}{2} + \\frac{\\sqrt{2} r}{2}\\end{array} \\right] \\]"
      ],
      "text/plain": [
       "3-element Array{Sym,1}:\n",
       "                                              -a1^2 + sqrt(2)*r*cos(θ)/2 + sqrt(2)*r/2\n",
       " -a1*a2*exp(I*α1)*exp(-I*α2) - sqrt(2)*I*r*sin(θ)*sin(ϕ)/2 + sqrt(2)*r*sin(θ)*cos(ϕ)/2\n",
       "                                              -a2^2 - sqrt(2)*r*cos(θ)/2 + sqrt(2)*r/2"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#  待解方程组\n",
    "\n",
    "eqs = [sum(k[μ]*σ[μ,Σ,Σ1] for μ in 1:4)-ξ[Σ]*conj(ξ[Σ1]) for Σ in 1:2, Σ1 in 1:2];\n",
    "eqs = [eqs[i,j] for i in 1:2, j in 1:2 if i <= j];\n",
    "eqs"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\[ \\left[ \\begin{array}{r}\\sqrt[4]{2} \\sqrt{r} \\cos{\\left(\\frac{θ}{2} \\right)}\\\\\\sqrt[4]{2} \\sqrt{r} \\sin{\\left(\\frac{θ}{2} \\right)}\\\\α2 - ϕ\\end{array} \\right] \\]"
      ],
      "text/plain": [
       "3-element Array{Sym,1}:\n",
       " 2^(1/4)*sqrt(r)*cos(θ/2)\n",
       " 2^(1/4)*sqrt(r)*sin(θ/2)\n",
       "                   α2 - ϕ"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 方程组求解\n",
    "\n",
    "rs = solve(eqs,[a1,a2,α1])[4] .|>  \n",
    "    (expr->expr(θ=>2*θ))  .|>  simplify.|>   # 三角化简：临时变量替换\n",
    "    (expr->refine(expr, Q.positive(cos(θ)) & Q.positive(sin(θ))))  .|>  simplify .|>  # 去除绝对值\n",
    "    (expr->expr(IM*(α2-ϕ)=>x)) .|>  simplify .|>  #  对数指数化简：临时变量替换\n",
    "    (expr->expr(x=>IM*(α2-ϕ),θ=>θ//2)); # 变量复原\n",
    "rs = [rs[i] for i in 1:3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\[ \\left[ \\begin{array}{r}\\sqrt[4]{2} \\sqrt{r} e^{i \\left(\\frac{α}{2} - \\frac{ϕ}{2}\\right)} \\cos{\\left(\\frac{θ}{2} \\right)}\\\\\\sqrt[4]{2} \\sqrt{r} e^{i \\left(\\frac{α}{2} + \\frac{ϕ}{2}\\right)} \\sin{\\left(\\frac{θ}{2} \\right)}\\end{array} \\right] \\]"
      ],
      "text/plain": [
       "2-element Array{Sym,1}:\n",
       " 2^(1/4)*sqrt(r)*exp(I*(α/2 - ϕ/2))*cos(θ/2)\n",
       " 2^(1/4)*sqrt(r)*exp(I*(α/2 + ϕ/2))*sin(θ/2)"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#  旋量分量确定 \n",
    "\n",
    "ξ=ξ .|> (expr->expr(a1=>rs[1],a2=>rs[2],α1=>rs[3]))   .|>  simplify .|>\n",
    "        (expr->expr(α2=>ϕ//2+α//2))  # 不确定因子调整"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\[\\left[ \\begin{array}{rr}0&0\\\\0&0\\end{array}\\right]\\]"
      ],
      "text/plain": [
       "2×2 Array{Sym,2}:\n",
       " 0  0\n",
       " 0  0"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 验证\n",
    "\n",
    "rs = [sum(k[μ]*σ[μ,Σ,Σ1] for μ in 1:4)-ξ[Σ]*conj(ξ[Σ1]) for Σ in 1:2, Σ1 in 1:2] \n",
    "\n",
    "rs  .|> real .|> simplify"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\[\\left[ \\begin{array}{rr}0&0\\\\0&0\\end{array}\\right]\\]"
      ],
      "text/plain": [
       "2×2 Array{Sym,2}:\n",
       " 0  0\n",
       " 0  0"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rs  .|> imag  .|> simplify"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##  旋量$\\eta^A$的分量\n",
    "\n",
    "确定依据【精确到可加上$c \\xi^A$】:\n",
    "\n",
    "$$\\xi_A\\eta^A=1$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\[ \\left[ \\begin{array}{r}\\sqrt[4]{2} c \\sqrt{r} e^{i \\left(\\frac{α}{2} - \\frac{ϕ}{2}\\right)} \\cos{\\left(\\frac{θ}{2} \\right)}\\\\\\sqrt[4]{2} c \\sqrt{r} e^{i \\left(\\frac{α}{2} + \\frac{ϕ}{2}\\right)} \\sin{\\left(\\frac{θ}{2} \\right)} + η2\\end{array} \\right] \\]"
      ],
      "text/plain": [
       "2-element Array{Sym,1}:\n",
       "      2^(1/4)*c*sqrt(r)*exp(I*(α/2 - ϕ/2))*cos(θ/2)\n",
       " 2^(1/4)*c*sqrt(r)*exp(I*(α/2 + ϕ/2))*sin(θ/2) + η2"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "@vars η1 η2 c\n",
    "\n",
    "#  η1 可以被 c*ξ吸收掉\n",
    "#  η2  待定\n",
    "#   c  手工调整，目标：使得两个分量的简单度一致\n",
    "η =[0,η2] + c*ξ"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\begin{equation*}- \\sqrt{2} c r e^{i \\left(\\frac{α}{2} - \\frac{ϕ}{2}\\right)} e^{i \\left(\\frac{α}{2} + \\frac{ϕ}{2}\\right)} \\sin{\\left(\\frac{θ}{2} \\right)} \\cos{\\left(\\frac{θ}{2} \\right)} + \\sqrt[4]{2} \\sqrt{r} \\left(\\sqrt[4]{2} c \\sqrt{r} e^{i \\left(\\frac{α}{2} + \\frac{ϕ}{2}\\right)} \\sin{\\left(\\frac{θ}{2} \\right)} + η2\\right) e^{i \\left(\\frac{α}{2} - \\frac{ϕ}{2}\\right)} \\cos{\\left(\\frac{θ}{2} \\right)} - 1\\end{equation*}"
      ],
      "text/plain": [
       "            ⎛α   ϕ⎞    ⎛α   ϕ⎞                          ⎛              ⎛α   ϕ⎞\n",
       "          ⅈ⋅⎜─ - ─⎟  ⅈ⋅⎜─ + ─⎟                          ⎜            ⅈ⋅⎜─ + ─⎟\n",
       "            ⎝2   2⎠    ⎝2   2⎠    ⎛θ⎞    ⎛θ⎞   4 ___    ⎜4 ___         ⎝2   2⎠\n",
       "- √2⋅c⋅r⋅ℯ         ⋅ℯ         ⋅sin⎜─⎟⋅cos⎜─⎟ + ╲╱ 2 ⋅√r⋅⎜╲╱ 2 ⋅c⋅√r⋅ℯ         \n",
       "                                  ⎝2⎠    ⎝2⎠            ⎝                     \n",
       "\n",
       "            ⎞    ⎛α   ϕ⎞           \n",
       "            ⎟  ⅈ⋅⎜─ - ─⎟           \n",
       "    ⎛θ⎞     ⎟    ⎝2   2⎠    ⎛θ⎞    \n",
       "⋅sin⎜─⎟ + η2⎟⋅ℯ         ⋅cos⎜─⎟ - 1\n",
       "    ⎝2⎠     ⎠               ⎝2⎠    "
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "eqs = sum(ϵ[Σ,Ω]*ξ[Σ]*η[Ω] for Σ in 1:2, Ω in 1:2)-1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\begin{equation*}\\frac{2^{\\frac{3}{4}} e^{\\frac{i \\left(- α + ϕ\\right)}{2}}}{2 \\sqrt{r} \\cos{\\left(\\frac{θ}{2} \\right)}}\\end{equation*}"
      ],
      "text/plain": [
       "      ⅈ⋅(-α + ϕ)\n",
       "      ──────────\n",
       " 3/4      2     \n",
       "2   ⋅ℯ          \n",
       "────────────────\n",
       "          ⎛θ⎞   \n",
       "  2⋅√r⋅cos⎜─⎟   \n",
       "          ⎝2⎠   "
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rs = solve(eqs,η2)[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\[ \\left[ \\begin{array}{r}- \\frac{2^{\\frac{3}{4}} e^{- \\frac{i \\left(α + ϕ\\right)}{2}} \\sin{\\left(\\frac{θ}{2} \\right)}}{2 \\sqrt{r}}\\\\\\frac{2^{\\frac{3}{4}} e^{- \\frac{i \\left(α - ϕ\\right)}{2}} \\cos{\\left(\\frac{θ}{2} \\right)}}{2 \\sqrt{r}}\\end{array} \\right] \\]"
      ],
      "text/plain": [
       "2-element Array{Sym,1}:\n",
       " -2^(3/4)*exp(-I*(α + ϕ)/2)*sin(θ/2)/(2*sqrt(r))\n",
       "  2^(3/4)*exp(-I*(α - ϕ)/2)*cos(θ/2)/(2*sqrt(r))"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 通过手工逐步调整c ，使得最复杂的分量变得更简单，直到两个分量的简单度一致 \n",
    "\n",
    "η=η .|> (expr->expr(η2=>rs)) .|> simplify .|>\n",
    "    (expr->expr(θ=>2*θ)) .|>  simplify  .|>   # 临时变量替换\n",
    "    (expr->expr(c=>c*tan(θ)/r)) .|>  simplify  .|>  # 目标：逐步将第二个分量简化\n",
    "    (expr->expr(c=>c*exp(-IM*α))) .|>  simplify .|>   \n",
    "    (expr->expr(c=>-sqrt(Sym(2))/2)) .|>  simplify  .|>\n",
    "    (expr->expr(θ=>θ//2))   .|> simplify  # 临时变量复原"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\begin{equation*}1\\end{equation*}"
      ],
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 验证\n",
    "\n",
    "sum(ϵ[Σ,Ω]*ξ[Σ]*η[Ω] for Σ in 1:2, Ω in 1:2)  .|>sympy.expand_trig .|> simplify "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 零模四维矢量$l^a$\n",
    "\n",
    "确定依据：\n",
    "\n",
    "$$l^\\mu\\sigma_\\mu^{\\ \\ AA'}= l^{AA'}=\\xi^A\\bar{\\eta}^{A'}+\\eta^A\\bar{\\xi}^{A'}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\[ \\left[ \\begin{array}{r}l_{0}\\\\l_{1}\\\\l_{2}\\\\l_{3}\\end{array} \\right] \\]"
      ],
      "text/plain": [
       "4-element Array{Sym,1}:\n",
       " l0\n",
       " l1\n",
       " l2\n",
       " l3"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "@vars l0 l1 l2 l3 real=true\n",
    "\n",
    "# 待定\n",
    "l=[l0,l1,l2,l3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\[ \\left[ \\begin{array}{r}- \\frac{\\sqrt{2} l_{0}}{2} - \\frac{\\sqrt{2} l_{3}}{2} - \\sin{\\left(θ \\right)} \\cos{\\left(α \\right)}\\\\- \\frac{\\sqrt{2} l_{1}}{2} - 2 \\sin^{2}{\\left(\\frac{θ}{2} \\right)} \\cos{\\left(α \\right)} \\cos{\\left(ϕ \\right)} + \\cos{\\left(α - ϕ \\right)}\\\\- \\frac{\\sqrt{2} l_{0}}{2} + \\frac{\\sqrt{2} l_{3}}{2} + \\sin{\\left(θ \\right)} \\cos{\\left(α \\right)}\\\\\\frac{\\sqrt{2} l_{2}}{2} + 2 \\sin^{2}{\\left(\\frac{θ}{2} \\right)} \\sin{\\left(ϕ \\right)} \\cos{\\left(α \\right)} + \\sin{\\left(α - ϕ \\right)}\\end{array} \\right] \\]"
      ],
      "text/plain": [
       "4-element Array{Sym,1}:\n",
       "            -sqrt(2)*l0/2 - sqrt(2)*l3/2 - sin(θ)*cos(α)\n",
       " -sqrt(2)*l1/2 - 2*sin(θ/2)^2*cos(α)*cos(ϕ) + cos(α - ϕ)\n",
       "            -sqrt(2)*l0/2 + sqrt(2)*l3/2 + sin(θ)*cos(α)\n",
       "  sqrt(2)*l2/2 + 2*sin(θ/2)^2*sin(ϕ)*cos(α) + sin(α - ϕ)"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "eqs = [ξ[Σ]*conj(η[Σ1])+η[Σ]*conj(ξ[Σ1])-sum(l[μ]*σ[μ,Σ,Σ1] for μ in 1:4) \n",
    "            for Σ in 1:2, Σ1 in 1:2] .|> simplify \n",
    "eqs = [eqs[i,j] for i in 1:2, j in 1:2 if i<=j];\n",
    "eqs_r = eqs .|> real .|> simplify ;\n",
    "eqs_i = eqs .|> imag .|> simplify ;\n",
    "eqs_i = [eqs_i[i] for i in 1:3 if eqs_i[i]!=0]\n",
    "eqs = vcat(eqs_r,eqs_i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Dict{Any,Any} with 4 entries:\n",
       "  l0 => 0\n",
       "  l2 => -sqrt(2)*(2*sin(θ/2)^2*sin(ϕ)*cos(α) + sin(α - ϕ))\n",
       "  l3 => -sqrt(2)*sin(θ)*cos(α)\n",
       "  l1 => sqrt(2)*(-2*sin(θ/2)^2*cos(α)*cos(ϕ) + cos(α - ϕ))"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rs = solve(eqs,l)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\[ \\left[ \\begin{array}{r}0\\\\\\sqrt{2} \\left(\\sin{\\left(α \\right)} \\sin{\\left(ϕ \\right)} + \\cos{\\left(α \\right)} \\cos{\\left(θ \\right)} \\cos{\\left(ϕ \\right)}\\right)\\\\\\sqrt{2} \\left(- \\sin{\\left(α \\right)} \\cos{\\left(ϕ \\right)} + \\sin{\\left(ϕ \\right)} \\cos{\\left(α \\right)} \\cos{\\left(θ \\right)}\\right)\\\\- \\sqrt{2} \\sin{\\left(θ \\right)} \\cos{\\left(α \\right)}\\end{array} \\right] \\]"
      ],
      "text/plain": [
       "4-element Array{Sym,1}:\n",
       "                                               0\n",
       "  sqrt(2)*(sin(α)*sin(ϕ) + cos(α)*cos(θ)*cos(ϕ))\n",
       " sqrt(2)*(-sin(α)*cos(ϕ) + sin(ϕ)*cos(α)*cos(θ))\n",
       "                          -sqrt(2)*sin(θ)*cos(α)"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "l = l .|> (expr->expr(l0=>rs[l0],l1=>rs[l1],l2=>rs[l2],l3=>rs[l3]))   .|>  \n",
    "       (expr->expr((sin(θ//2))^2=>(1-cos(θ))//2)) .|>sympy.expand_trig .|> simplify "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\begin{equation*}2\\end{equation*}"
      ],
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sum(g[μ,υ]*l[μ]*l[υ] for μ in 1:4, υ in 1:4) .|> simplify "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 旗$F^{ab}$\n",
    "\n",
    "$$F^{ab}=k^a l^b- l^a k^b$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\[\\left[ \\begin{array}{rrrr}0&\\sqrt{2} r \\left(\\sin{\\left(α \\right)} \\sin{\\left(ϕ \\right)} + \\cos{\\left(α \\right)} \\cos{\\left(θ \\right)} \\cos{\\left(ϕ \\right)}\\right)&\\sqrt{2} r \\left(- \\sin{\\left(α \\right)} \\cos{\\left(ϕ \\right)} + \\sin{\\left(ϕ \\right)} \\cos{\\left(α \\right)} \\cos{\\left(θ \\right)}\\right)&- \\sqrt{2} r \\sin{\\left(θ \\right)} \\cos{\\left(α \\right)}\\\\- \\sqrt{2} r \\left(\\sin{\\left(α \\right)} \\sin{\\left(ϕ \\right)} + \\cos{\\left(α \\right)} \\cos{\\left(θ \\right)} \\cos{\\left(ϕ \\right)}\\right)&0&- \\sqrt{2} r \\sin{\\left(α \\right)} \\sin{\\left(θ \\right)}&- \\sqrt{2} r \\left(\\sin{\\left(α \\right)} \\sin{\\left(ϕ \\right)} \\cos{\\left(θ \\right)} + \\cos{\\left(α \\right)} \\cos{\\left(ϕ \\right)}\\right)\\\\\\sqrt{2} r \\left(\\sin{\\left(α \\right)} \\cos{\\left(ϕ \\right)} - \\sin{\\left(ϕ \\right)} \\cos{\\left(α \\right)} \\cos{\\left(θ \\right)}\\right)&\\sqrt{2} r \\sin{\\left(α \\right)} \\sin{\\left(θ \\right)}&0&\\sqrt{2} r \\left(\\sin{\\left(α \\right)} \\cos{\\left(θ \\right)} \\cos{\\left(ϕ \\right)} - \\sin{\\left(ϕ \\right)} \\cos{\\left(α \\right)}\\right)\\\\\\sqrt{2} r \\sin{\\left(θ \\right)} \\cos{\\left(α \\right)}&\\sqrt{2} r \\left(\\sin{\\left(α \\right)} \\sin{\\left(ϕ \\right)} \\cos{\\left(θ \\right)} + \\cos{\\left(α \\right)} \\cos{\\left(ϕ \\right)}\\right)&\\sqrt{2} r \\left(- \\sin{\\left(α \\right)} \\cos{\\left(θ \\right)} \\cos{\\left(ϕ \\right)} + \\sin{\\left(ϕ \\right)} \\cos{\\left(α \\right)}\\right)&0\\end{array}\\right]\\]"
      ],
      "text/plain": [
       "4×4 Array{Sym,2}:\n",
       "                                                 0  …                           -sqrt(2)*r*sin(θ)*cos(α)\n",
       " -sqrt(2)*r*(sin(α)*sin(ϕ) + cos(α)*cos(θ)*cos(ϕ))     -sqrt(2)*r*(sin(α)*sin(ϕ)*cos(θ) + cos(α)*cos(ϕ))\n",
       "  sqrt(2)*r*(sin(α)*cos(ϕ) - sin(ϕ)*cos(α)*cos(θ))      sqrt(2)*r*(sin(α)*cos(θ)*cos(ϕ) - sin(ϕ)*cos(α))\n",
       "                           sqrt(2)*r*sin(θ)*cos(α)                                                     0"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "F = [k[μ]*l[υ]-l[μ]*k[υ] for μ in 1:4, υ in 1:4] .|>sympy.expand_trig .|> simplify "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\begin{equation*}0\\end{equation*}"
      ],
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 验证\n",
    "\n",
    "det(F)  .|> sympy.expand_trig .|> simplify "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Julia 1.5.2",
   "language": "julia",
   "name": "julia-1.5"
  },
  "language_info": {
   "file_extension": ".jl",
   "mimetype": "application/julia",
   "name": "julia",
   "version": "1.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
